﻿using System;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;

namespace GUI.Controls.Sport
{
    public partial class HighlightNewsInCategory2 : System.Web.UI.UserControl
    {
        private const string TopItemFormat = "{3}<div class=\"desc\"><h2><a href=\"{0}\" title=\"{2}\">{1}{5}</a></h2><p>{4}</p></div>";
        private const string LiFormat = "<li>{3}<h2><a href=\"{0}\" title=\"{2}\">{1}{4}</a></h2></li>";
        private const string BottomItemFormat = "<li><h2><a href=\"{0}\" title=\"{2}\">{1}{5}</a></h2>{4}<p>{3}</p></li>";
        private const int ImageWidth1 = 500;
        private const int ImageHeight1 = 355;
        private const int ImageWidth2 = 150;
        private const int ImageHeight2 = 90;
        private const int ImageWidth3 = 310;
        private const int ImageHeight3 = 205;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        internal bool DataBind(System.Data.DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                for (var i = 0; i < dt.Rows.Count; i++)
                {
                    var r = dt.Rows[i];
                    switch (i)
                    {
                        case 0:
                            {
                                var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth1, ImageHeight1, lazyLoad: true);
                                ltrTopItem.Text = string.Format(TopItemFormat,
                                    r[SqlConstants.NewsPublish.Url],
                                    r[SqlConstants.NewsPublish.Title],
                                    PresentationUtils.EnCode(r[SqlConstants.NewsPublish.Title].ToString()),
                                    avatar,
                                    r[SqlConstants.NewsPublish.InitSapo],
                                    r[SqlConstants.NewsPublish.NewsTypeIcon]);
                                break;
                            }
                        case 1:
                        case 2:
                        case 3:
                            {
                                var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth2, ImageHeight2, lazyLoad: true);
                                ltrRight.Text += string.Format(LiFormat,
                                                               r[SqlConstants.NewsPublish.Url],
                                                               r[SqlConstants.NewsPublish.Title],
                                                               PresentationUtils.EnCode(r[SqlConstants.NewsPublish.Title].ToString()),
                                                               avatar,
                                                               r[SqlConstants.NewsPublish.NewsTypeIcon]);
                                break;
                            }
                        case 4:
                        case 5:
                            {
                                var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth3, ImageHeight3,lazyLoad:true);
                                ltrBottomItem.Text += string.Format(BottomItemFormat,
                                                               r[SqlConstants.NewsPublish.Url],
                                                               r[SqlConstants.NewsPublish.Title],
                                                               PresentationUtils.EnCode(r[SqlConstants.NewsPublish.Title].ToString()),
                                                               r[SqlConstants.NewsPublish.InitSapo],
                                                               avatar,
                                                               r[SqlConstants.NewsPublish.NewsTypeIcon]);
                                break;
                            }
                        default:
                            {

                                break;
                            }
                    }
                }
                return true;
            }
            return false;
        }
    }
}